using System;
using System.Collections.Generic;
using System.Text;

namespace Wax
{
    /// <summary>
    /// Represents a test error, which comprises of the <see cref="Command"/> and it's associated <see cref="Test"/> that
    /// were executing when a <see cref="CommandException"/> was encountered.
    /// </summary>
    public class TestError
    {
        /// <summary>
        /// The exception that has been encountered during the execution of a test.
        /// </summary>
        private readonly CommandException exception;

        /// <summary>
        /// The test that was being executed when the exception occured.
        /// </summary>
        private readonly Test test;

        /// <summary>
        /// Initializes a new instance of the <see cref="TestError"/> class.
        /// </summary>
        /// <param name="exception">The exception.</param>
        /// <param name="test">The test.</param>
        public TestError(CommandException exception, Test test)
        {
            this.exception = exception;
            this.test = test;
        }

        /// <summary>
        /// The exception that has been encountered during the execution of a test.
        /// </summary>
        public CommandException Exception
        {
            get { return exception; }
        }

        /// <summary>
        /// The test that was being executed when the exception occured.
        /// </summary>
        public Test Test
        {
            get { return test; }
        }

        /// <summary>
        /// The command that was being executed when the exception occured.
        /// </summary>
        public Command Command
        {
            get { return exception.Command; }
        }

        /// <summary>
        /// Returns a <see cref="T:System.String"></see> that represents the current <see cref="T:System.Object"></see>.
        /// </summary>
        /// <returns>
        /// A <see cref="T:System.String"></see> that represents the current <see cref="T:System.Object"></see>.
        /// </returns>
        public override string ToString()
        {
            StringBuilder errorToString = new StringBuilder();

            errorToString.Append(this.Test.ToString() + System.Environment.NewLine);
            errorToString.Append(this.exception.ToString());

            return errorToString.ToString();
        }
    }
}
